package TwentyOne.Class.Jc;

/*
 *  统计出字符串“want you to know one thing”中字母n和字母o的出现次数。
 */
class StringUtil {

    // 返回第一个内容为字母n的个数，第二个内容为字母o的个数
    public static int[] count(String str) {
        int countData[] = new int[2];
        char[] data = str.toCharArray();  //将字符串变为字符数组
        for (int i = 0; i < data.length; i++) {
            if (data[i] == 'n' || data[i] == 'N') {
                countData[0]++;
            }
            if (data[i] == 'o' || data[i] == 'O') {
                countData[1]++;
            }

        }
        return countData;
    }
}

public class a15_Ex1 {

    public static void main(String[] args) {
        String str = "want you to know one thing";
        int result[] = StringUtil.count(str);
        System.out.println("字母n的个数：" + result[0]);
        System.out.println("字母o的个数：" + result[1]);
    }
}
